package com.example.message_wall.controller;

import com.example.message_wall.mapper.MessageMapper;
import com.example.message_wall.model.MessageInfo;
import com.example.message_wall.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageWall_controller {
    private List<MessageInfo> database = new ArrayList<>();
    @Autowired
    private MessageService service;
    @Autowired
    private MessageMapper mapper;
    @RequestMapping("/publish")
    public boolean submit(MessageInfo messageInfo) {
        if(!service.check(messageInfo)) {
            return false;
        }
         //插入数据
        mapper.insertMessage(messageInfo);
        return true;
    }

    @RequestMapping("/getMessage")
    public List<MessageInfo> getMessage() {
        return mapper.queryAllMessage();
    }

}
